package com.example.function.integration.enums;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

/**
 * @description:业务类型枚举
 * @className:BizTypeEnum
 * @author:ext.fengcheng
 * @date:2023/11/20 17:10
 */
public enum BizTypeEnum {
    LEND("LEND", "放款"),
    LEND_PHASE_I("LEND_PHASE_I", "还款一期"),
    LEND_PHASE_II("LEND_PHASE_II", "还款二期"),
    LEND_PHASE_III("LEND_PHASE_III", "还款三期"),
    LEND_PHASE_IIII("LEND_PHASE_IIII", "还款四期"),
    LEND_PHASE_FIVE("LEND_PHASE_FIVE", "还款五期"),
    LEND_PHASE_SIX("LEND_PHASE_SIX", "还款六期"),
    LEND_PHASE_SEVEN("LEND_PHASE_SEVEN", "还款七期"),
    LEND_PHASE_EIGHTH("LEND_PHASE_EIGHTH", "还款八期"),
    LEND_PHASE_NINTH("LEND_PHASE_NINTH", "还款九期"),
    LEND_PHASE_TEN("LEND_PHASE_TEN", "还款十期"),
    LEND_PHASE_ELEVENTH("LEND_PHASE_ELEVENTH", "还款十一期"),
    LEND_PHASE_TWELVE("LEND_PHASE_TWELVE", "还款十二期"),
    OVERDUE_BORROWINGS("OVERDUE_BORROWINGS", "逾期借款"),
    ;

    private final String code;
    private final String desc;

    BizTypeEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public String getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    private static final Map<String, BizTypeEnum> map = new HashMap<>();

    static {
        BizTypeEnum[] values = values();
        for (BizTypeEnum temp : values) {
            map.put(temp.getCode(), temp);
        }
    }

    public static BizTypeEnum getEnumByCode(String code) {
        return map.get(code);
    }

    public static BizTypeEnum getEnumByDesc(String desc) {
        AtomicReference<BizTypeEnum> bizTypeEnum = new AtomicReference<>();
        map.forEach((key, value) -> {
            if (value.getDesc().equals(desc)) {
                bizTypeEnum.set(value);
            }
        });
        return bizTypeEnum.get();
    }
}
